import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'home',
      meta: { title: "学生列表" },
      component: () => import("@/views/Home.vue"),
    },
    {
      path: '/addStudent',
      name: 'addStudent',
      meta: { title: "新增学生" },
      component: () => import("@/views/AddStudent.vue"),
    },
    {
      path: '/updateStudent/:id',
      name: 'updateStudent',
      meta: { title: "修改学生" },
      component: () => import("@/views/UpdateStudent.vue"),
    },
  ],
})

// 全局守卫
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
